<template>
  <basic-container>
    <avue-crud
        v-bind="bindVal"
        v-on="onEvent"
        :page.sync="page"
        v-model="startForm">
      <template slot="menuLeft">
        <el-button type="primary" size="small">暂停全部任务</el-button>
        <el-button type="primary" size="small">恢复全部任务</el-button>
      </template>
      <template slot-scope="{type,size,row}" slot="menuBtn">
        <el-dropdown-item icon="el-icon-edit" :size="size" @click.native="activeTask(row)" :type="type">激活任务
        </el-dropdown-item>
        <el-dropdown-item icon="el-icon-edit" :size="size" @click.native="disableTask(row)" :type="type">停止任务
        </el-dropdown-item>
        <el-dropdown-item icon="el-icon-edit" :size="size" @click.native="pauseTask(row)" :type="type">暂停任务
        </el-dropdown-item>
        <el-dropdown-item icon="el-icon-edit" :size="size" @click.native="recoveryTask(row)" :type="type">恢复任务
        </el-dropdown-item>
        <el-dropdown-item icon="el-icon-edit" :size="size" @click.native="startTask(row)" :type="type">立即执行
        </el-dropdown-item>
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import startCrud from "@/mixins/start-crud.js"
import {startById, activeById, disableById, pauseAll, pauseById, recoveryById, recoveryAll} from "@/api/start/quartzApi";

export default startCrud({
      components: {},
      data() {
        return {};
      },
      created() {

      },
      methods: {
        activeTask(row) {
          this.$confirm(`是否激活名称为【${row.name}】的任务?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            return activeById(row.id)
          }).then(res => {
            this.$message.success("激活任务成功");
            this.refreshChange()
          })
        },
        disableTask(row) {
          this.$confirm(`是否停用名称为【${row.name}】的任务?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            return disableById(row.id)
          }).then(res => {
            this.$message.success("停用任务成功");
            this.refreshChange()
          })
        },
        pauseTask(row) {
          this.$confirm(`是否暂停名称为【${row.name}】的任务?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            return pauseById(row.id)
          }).then(res => {
            this.$message.success("暂停任务成功");
            this.refreshChange()
          })
        },
        recoveryTask(row) {
          this.$confirm(`是否恢复名称为【${row.name}】的任务?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            return recoveryById(row.id)
          }).then(res => {
            this.$message.success("恢复任务成功");
            this.refreshChange()
          })
        },
        startTask(row) {
          this.$confirm(`是否立即执行名称为【${row.name}】的任务?`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            return startById(row.id)
          }).then(res => {
            this.$message.success("立即执行任务成功");
            this.refreshChange()
          })
        },

      }
    },
    {
      name: "start/quartz"
    }
)
</script>

<style scoped>

</style>
